﻿module Supernova {

    export class ShipOrder {

        public type: ShipOrderType;

        public targetLocation: Location = null;

        constructor() {
        }

        public static create(type: ShipOrderType): ShipOrder {
            var order = new ShipOrder();
            order.type = type;
            return order;
        }

        public static createWithShip(type: ShipOrderType, ship: Ship) {
            var order = ShipOrder.create(type);
            order.targetLocation = new Location();
            order.targetLocation.setShip(ship);
            return order;
        }

        public static createWithBody(type: ShipOrderType, body: Body) {
            var order = ShipOrder.create(type);
            order.targetLocation = new Location();
            order.targetLocation.setBody(body);
            return order;
        }

        public static createWithSystem(type: ShipOrderType, system: StarSystem) {
            var order = ShipOrder.create(type);
            order.targetLocation = new Location();
            order.targetLocation.setSystem(system);
            return order;
        }

        public static createWithLocation(type: ShipOrderType, x: number, y: number) {
            var order = ShipOrder.create(type);
            order.targetLocation = new Location();
            order.targetLocation.setXY(x, y);
            return order;
        }

        public describe(): string {
            switch (this.type) {
                case ShipOrderType.move:
                case ShipOrderType.explore:
                    var s = this.type == ShipOrderType.move ? 'Move' : 'Explore';
                    if (this.targetLocation == null) return s;
                    if (this.targetLocation.ship !== null) return s + ' Ship';
                    if (this.targetLocation.body !== null) return s + ' Body';
                    if (this.targetLocation.system !== null) return s + ' System ' + this.targetLocation.system.name;
                    return s + ' Fixed Location (' + this.targetLocation.x + ', ' + this.targetLocation.y + ')';

                case ShipOrderType.bombard: return 'Bombard';
                case ShipOrderType.colonise: return 'Colonise';
                case ShipOrderType.disband: return 'Disband';
                case ShipOrderType.repair: return 'Repair';
                case ShipOrderType.terraform: return 'Terraform';
                default: return 'Unknown';
            }
        }

    }

}